package com.example.yls.demoa;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class RegActivity extends AppCompatActivity {
    private EditText editUserName;
    private EditText editPassword;
    private EditText edtname;
    private EditText edtage;
    private Button btnSign;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        btnSign = findViewById(R.id.btn_sign);
        editUserName = findViewById(R.id.edt_UserName);
        editPassword = findViewById(R.id.edt_Password);
        edtname = findViewById(R.id.edt_name);
        edtage = findViewById(R.id.edt_age);
        btnSign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                regUser();
            }
        });

    }

    private void regUser() {
        String username =editUserName.getText().toString();
        String password =editPassword.getText().toString();
        String name =edtname.getText().toString();
        int age =Integer.valueOf(edtage.getText().toString());
        MyUser myUser= new MyUser();
        myUser.setUsername(username);
        myUser.setPassword(password);
        myUser.setName(name);
        myUser.setAge(age);
        myUser.signUp(new SaveListener<MyUser>() {
            @Override
            public void done(MyUser myUser, BmobException e) {
                if(e==null){
                    Toast.makeText(RegActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
                }
            }

        });

    }
}
